package com.petalsgroup.petals.service.user.impl;

import com.petalsgroup.petals.dao.Animation.AnimationDao;
import com.petalsgroup.petals.dao.Animation.impl.AnimationDaoImpl;
import com.petalsgroup.petals.dao.user.MySelfDao;
import com.petalsgroup.petals.dao.user.impl.MySelfDaoImpl;
import com.petalsgroup.petals.pojo.AnimationSimpleDO;
import com.petalsgroup.petals.pojo.AnimationSimpleVO;
import com.petalsgroup.petals.pojo.UserDO;
import com.petalsgroup.petals.service.user.MySelfService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MySelfServiceImpl implements MySelfService {
    private MySelfDao myselfDao = new MySelfDaoImpl();
    private AnimationDao animationDao = new AnimationDaoImpl();

    @Override
    public Boolean updateUser(UserDO user) {
        Boolean bool = myselfDao.updateUser(user);
        if (bool){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public List<AnimationSimpleVO> findAidByUid(Integer uid) {
        List<AnimationSimpleVO> list =new ArrayList<>();
        //通过uid查aid
        List<AnimationSimpleDO> aidByUid = myselfDao.findAidByUid(uid);
        //通过aid查动漫信息
        for (AnimationSimpleDO animationSimpleDO: aidByUid) {
            AnimationSimpleVO animationSimpleVO = new AnimationSimpleVO();
            AnimationSimpleDO animationSimple = animationDao.getAnimationSimple(animationSimpleDO.getAid());
            animationSimpleVO.setAnimationSimple(animationSimple);
            list.add(animationSimpleVO);
        }
        return list;
    }

    @Override
    public List<AnimationSimpleVO> findCollectByAname(String name) {
        ArrayList<AnimationSimpleVO> list = new ArrayList<>();
        List<AnimationSimpleDO> animationSimpleDOList = animationDao.findAnimationByAname(name);
        //System.out.println(animationSimpleDOList);
        for (AnimationSimpleDO a:animationSimpleDOList) {
            AnimationSimpleVO animationSimpleVO = new AnimationSimpleVO();
            animationSimpleVO.setAnimationSimple(a);
            list.add(animationSimpleVO);
        }
        return list;
    }

    @Override
    public Boolean cancelCollect(Integer aid, Integer uid) {
        return animationDao.removeCollect(aid,uid);
    }

    @Override
    public UserDO findUidByUsername(String username) {
        UserDO user = myselfDao.findUidByUsername(username);
        return user;
    }

    @Override
    public Boolean findAttention(Integer uid, Integer uided) {
        Boolean b = myselfDao.findAttention(uid,uided);

        return b;
    }

    @Override
    public void saveAttention(Integer uid, Integer uided) {
        myselfDao.saveAttention(uid,uided);
    }

    @Override
    public Integer findAttentionNum(Integer uid) {
        Integer num = myselfDao.findAttentionNum(uid);
        return num;
    }

}
